﻿using ConfExpert.Forms.Base;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

using DevTeam;
using ConfExpert.Utility;
using ConfExpert.Datasets;
using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Repository;

namespace ConfExpert.Forms.Depo
{
    public partial class DepoIciSatis : XForm
    {
        private string RollIds;
        private bool IkiFarkliOwnerIdVar = false;
        private DataTable ComboItems;
        private int CustomerId;
        private String CustomerName;
        //private bool DoUpdate = true;
        public DepoIciSatis(string RollIds, int CustomerId, String CustomerName)
        {
            this.RollIds = RollIds;
            this.CustomerId = CustomerId;
            this.CustomerName = CustomerName;
            InitializeComponent();
        }

        private void DepoIciSatis_Load(object sender, EventArgs e)
        {
            this.Text = "Depo İçi Satış";

            //gleOwner.Properties.Assign(RI(Rp.V_Customer));

            DataTable dt = ExecuteDataTable("GetComboBoxItems", RollIds);
            //RepositoryItemGridLookUpEdit riCustomers = GetCustomGLE(dt, "Name", "CustomerId");
            //gleOwner.Properties.Assign(riCustomers);



            gridView1.Init("GetDepoIciSatis", RollIds);
            gridView1.FormatAsNumber(1, "Qty");
            gridView1.MakeColumnsReadOnly("ProductId", "OwnerId", "Qty");
            gridView1.SetCaptions("Qty:ToplamMetraj");
            MyData.CustomerDataTable cdt = AppSession.Lookups.Customer;
            gridView1.BestFitColumns();
            btnKaydet.ItemClick += btnKaydet_ItemClick;
            
            //Musteri Adini Label a Bas
            lblNewOwner.Text = "Yeni Mal Sahibi " + CustomerName + " Olacak";

            //ComboItems = ExecuteDataTable("GetComboBoxItems", RollIds);
            //if (ComboItems.Rows.Count == 2)
            //    IkiFarkliOwnerIdVar = true;
        }

        void btnKaydet_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            // Musteri ID yi bu metoda gonder
            ExecuteNonQuery("UpdOwnerIdsInRoll", RollIds, CustomerId, WhoAmI);//cmbOwner.SelectedIndex);

            this.DialogResult = System.Windows.Forms.DialogResult.OK;


        }

        private String GetOtekiSelectedTextFromCombo(String SelectedText)
        {
            for (int i = 0; i < ComboItems.Rows.Count; ++i)
                if (!ComboItems.Rows[i]["Name"].ToStr().Equals(SelectedText))
                    return ComboItems.Rows[i]["Name"].ToStr();
            return "***";
        }

        private int GetOtekiValueFromCombo(int Value)
        {
            for (int i = 0; i < ComboItems.Rows.Count; ++i)
                if (ComboItems.Rows[i]["CustomerId"].ToInt() != Value)
                    return ComboItems.Rows[i]["CustomerId"].ToInt();
            return 0;
        }
        
    }
}
